# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html


# useful for handling different item types with a single interface
from itemadapter import ItemAdapter
import json

class Example08Pipeline:
    
    def open_spider(self, spider):
        with open('data.json') as f:
            self.data = json.load(f)
    
    def process_item(self, item, spider):
        
        self.data.append({
            'title': item['title'],
            'url': item['url']
        })
        return item

    def close_spider(self, spider):
        print(self.data)
        with open('data.json', 'w') as f:
            json.dump(self.data, f,ensure_ascii=False)